package net.dgg.dggcloud.service.jrcrm.service.pro;

import net.dgg.dggcloud.core.idwork.KeyWorker;
import net.dgg.dggcloud.core.minidao.hibernate.dao.IGenericBaseCommonDao;
import net.dgg.dggcloud.core.util.StringUtils;
import net.dgg.dggcloud.service.common.base.service.BaseService;
import net.dgg.dggcloud.service.common.exception.BizException;
import net.dgg.dggcloud.service.jrcrm.dao.pro.ProductAreaPriceDao;
import net.dgg.dggcloud.service.jrcrm.dao.pro.ProductDao;
import net.dgg.dggcloud.service.jrcrm.entity.cms.TreeBook;
import net.dgg.dggcloud.service.jrcrm.entity.pro.Product;
import net.dgg.dggcloud.service.jrcrm.entity.pro.ProductAreaPrice;
import net.dgg.dggcloud.service.jrcrm.entity.pro.ProductChannel;
import net.dgg.dggcloud.service.jrcrm.entity.pro.ProductCondition;
import net.dgg.dggcloud.service.entity.user.User;
import net.dgg.dggcloud.service.jrcrm.service.cms.BillNumberRuleService;
import net.dgg.dggcloud.service.jrcrm.service.cms.TreeBookService;
import net.dgg.dggcloud.service.jrcrm.vo.ProductVo;
import net.dgg.dggcloud.service.jrcrm.vo.ValidateResult;
import net.dgg.dggcloud.service.service.organization.OrganizationService;
import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * Created by Administrator on 2017/11/3.
 */
@Service
public class ProductService extends BaseService {

    @Autowired
    private ProductDao productDao;

    @Autowired
    private ProductAreaPriceDao productAreaPriceDao;

    @Autowired
    private ProductConditionService productConditionService;

    @Autowired
    private TreeBookService treeBookService;

    @Resource(name = "miniDaoHiberCommonDao")
    protected IGenericBaseCommonDao repository;

    @Autowired
    protected KeyWorker keyWorker;

    @Resource
    private BillNumberRuleService bs ;
    @Autowired
    private ProductChannelService productChannelService;
    @Resource
    private OrganizationService organizationService;


    /**
     *  根据ID，查询单个产品信息
     * @param id
     * @return
     */
    public Product getByIdHiber(Long id){
        return this.repository.get(Product.class,id);
    }

    public void setProductDao(ProductDao productDao) {
        this.productDao = productDao;
    }

    public void setRepository(IGenericBaseCommonDao repository) {
        this.repository = repository;
    }

    public void setProductAreaPriceDao(ProductAreaPriceDao productAreaPriceDao) {
        this.productAreaPriceDao = productAreaPriceDao;
    }

    public void setProductConditionService(ProductConditionService productConditionService) {
        this.productConditionService = productConditionService;
    }

    public Long countProduct(Map map){
        return productDao.countProductByMap(map);
    }

    public List<Product> getHistoryById(Long id){
        // order by version DESC limit 0,10
        Query query = repository.getSession().createQuery("from Product p1 where p1.serialNo = (select p2.serialNo from Product p2 where p2.id =?) order by p1.version DESC");
        query.setParameter(0,id);
        query.setFirstResult(1);
        query.setMaxResults(10);
        List<Product> list = query.list();
        return list;
    }

    public Integer getMaxVersionById(Long id){
        Query query = repository.getSession().createQuery("select max(version)  from Product p1 where p1.serialNo = (select p2.serialNo from Product p2 where p2.id =?)");
        query.setParameter(0,id);

        Integer max = (Integer)query.uniqueResult();
        return max;
    }

    public List<ProductChannel> queryChannelsByProductId(Long productId){
        List<ProductChannel> result = new ArrayList<>();

        Product product = repository.get(Product.class,productId);
        String channelIdsStr = product.getChannel();

        if(!StringUtils.isBlank(channelIdsStr)){
            String[] channelIdArr = channelIdsStr.split(",");
            if(null != channelIdArr && channelIdArr.length > 0){
                for(String currIdStr : channelIdArr){
                    Long currChannelId = Long.parseLong(currIdStr);
                    ProductChannel productChannel = repository.get(ProductChannel.class,currChannelId);
                    result.add(productChannel);
                }
            }
        }
        return result;

    }

    /**
    *@Description: 获取product（产品）简单详情，不包含producAreaPrice 和 productCondition信息
    *@Author: litao
    *@Param:map
    *@Date:16:28 2017/11/3
    */
    public List<Map> listProductByMap(Map map){
        return this.productDao.listProductByMap(map);
    }

    /**
    *@Description: 获取product（产品）详情，包含producAreaPrice 和 productCondition信息，<br />
     *              根据‘ids’（productId 集合,如：“1，2，3”） 是否有值分别查询，如果‘ids’有值，则按ids集合查询；<br />
     *              如果'ids’没有值，则根据type、name、channel组合查询。<br />
    *@Author: litao
    *@Param:map 查询条件 <br />
     *          type:一级类型
     *          name:产品id
     *          chnnel：产品渠道
     *          ids：产品集合
     *          status：状态
    *@Date:16:28 2017/11/3
    */
    public List<Map> listDetailProduct(Map map){

        List<ProductChannel> productChannels = getAllChannel();

        List<Map> result = new ArrayList<>();
        String arryIds = (String) map.get("ids");

        List<Map> simpleProductList = null;
        if(null != arryIds && arryIds.length() >=0){
            simpleProductList = this.productDao.listProductById(map);
        }else{
            simpleProductList = this.productDao.listProductByMap(map);
        }

        if(null == simpleProductList || simpleProductList.size() <= 0)
        {
            return result;
        }
        for(Map product : simpleProductList){

            Map<Object,Object> currentDetail = new HashMap<>();

            /***********拼接渠道名称**********/
            String channelIds = (String)product.get("channel");
            String channelNames = "";
            if(!StringUtils.isBlank(channelIds)){
                String[] channelIdArr = channelIds.split(",");
                if(channelIdArr!=null && channelIdArr.length>0){
                    for(String curIdstr : channelIdArr){
                        if(!StringUtils.isBlank(curIdstr)){
                            Long cid = Long.parseLong(curIdstr);
                            String  channelName = getByidInList(productChannels,cid);
                            if(!StringUtils.isBlank(channelName))
                            {
                                channelNames += channelName +",";
                            }
                        }
                    }

                }
            }
            if(!StringUtils.isBlank(channelNames)){
                channelNames = channelNames.substring(0,channelNames.lastIndexOf(","));
            }
            product.put("channelname",channelNames);
            /***********拼接渠道名称END**********/

            /** 将interestratemode 另存为 interestratecode **/
            product.put("interestratecode",product.get("interestratemode"));
            /** 将type 另存为 typecode **/
            product.put("typecode",product.get("type"));
            currentDetail.put("product",product);
            Long currentProID = (Long) product.get("id");

            Map paramap = new HashMap();
            paramap.put("productId",currentProID);

            List<Map> cuurrentAreaPrice = productAreaPriceDao.listProductAreaPriceByProductId(paramap);

            /***********获取当前登录用户所在区域**********/
            Boolean isGetUserArea = map.get("getWorkArea") == null ? false : (Boolean) map.get("getWorkArea");
            if(isGetUserArea){
                User currUser = (User) map.get("currUser");
                if(currUser != null){
//                    String userWorkArea = currUser.getWorkArea();
                    Long userWorkArea = organizationService.getOrganizationDepartmentId(currUser.getOrgId());

                    if(userWorkArea!= null){
                        for(Map areaMap : cuurrentAreaPrice){
                            String currAreaCode = (String)areaMap.get("area");
                            if(userWorkArea.toString().equals(currAreaCode)){
                                product.put("userarea",areaMap);
                                break;
                            }
                        }
                    }
                }
            }
            /***********获取当前登录用户所在区域END**********/

            List<Map> cuurrentCondition = productConditionService.listProductConditionByProductId(paramap);

            /***********拼接所需资料的名称**********/
            //原件：1
            if(null != arryIds && arryIds.length() >=0){

                List<Map> treeCardList = treeBookService.queryTreeBookListByCode("ORF_ZHZL",2);
                for(Map cond : cuurrentCondition){

                    String needDataString = (String)cond.get("needdata");
                    if(StringUtils.isNotBlank(needDataString)){
                        String[] needDataCodeArray = needDataString.split(",");

                        Map<String,String> needDataNameMap = new HashMap<>();
                        for(String currCode : needDataCodeArray){
                            String treeCode = currCode.substring(0,currCode.lastIndexOf("_"));
                            String iscopy = currCode.substring(currCode.lastIndexOf("_")+1);

                            for(Map curTreeCard : treeCardList){
                                String curTreeCode = (String)curTreeCard.get("code");
                                String curTreeName = (String)curTreeCard.get("name");
                                if(treeCode.equals(curTreeCode)){
                                    String isCopyName = "1".equals(iscopy)  ? "原件" : "复印件";
                                    if(!needDataNameMap.containsKey(curTreeName)){
                                        needDataNameMap.put(curTreeName,isCopyName);
                                    }else {
                                        needDataNameMap.put(curTreeName,needDataNameMap.get(curTreeName)
                                                + " " + isCopyName );
                                    }
                                }
                            }
//                        TreeBook treeBook = treeBookService.queryTreeBookByCode(treeCode);
//                        String isCopyName = "1".equals(iscopy)  ? "原件" : "复印件";
                        }
                        String neddDataNameString = "";
                        for(String key : needDataNameMap.keySet()){
                            neddDataNameString = neddDataNameString + key + "("+needDataNameMap.get(key)+")" + ",";
                        }
                        neddDataNameString = neddDataNameString.substring(0,neddDataNameString.lastIndexOf(","));

                        cond.put("needdataname",neddDataNameString);
                    }else{
                        cond.put("needdataname","");
                    }
                }

            }
            /***********拼接所需资料的名称END**********/


            currentDetail.put("productAreaPrice",cuurrentAreaPrice);
            currentDetail.put("productCondition",cuurrentCondition);

            result.add(currentDetail);
        }

        return result;
    }

    private List<ProductChannel> getAllChannel(){
        List<ProductChannel> productChannels = productChannelService.getAllChannel();
        return productChannels;
    }

    private String getByidInList(List<ProductChannel> list , Long id){
        String result = "";
        if(null != list && list.size() > 0){
            for(ProductChannel channel : list){
                if(id.longValue() == channel.getId().longValue()){
                    result=channel.getName();
                    break;
                }
            }
        }
        return result;
    }

    public void updateDetailProduct(ProductVo vo){


        ValidateResult result = validateProductParam(vo);
        if(!result.getSuccess()){
            throw new BizException(result.getMsg(),0); //// TODO: 2017/11/6 是否允许抛出异常
        }


    }


    /**
     *@Description: 保存产品包含区域价格和准入条件，异常抛出BizException
     *@Author: litao
     *@Param: vo ： 保存的实体对象（包含：Product、ProductAreaPrice、ProductCondition） <br />
     *        isPush : 是否上架 <br />
     *@Date:9:17 2017/11/7
     */
    public void saveOneDetailProduct(ProductVo vo, boolean isPush,User currUser){

        TreeBook treeBook = treeBookService.queryTreeBookParentByCode(vo.getProduct().getProClass());
        vo.getProduct().setType(treeBook.getPcode());

        ValidateResult result = validateProductParam(vo);
        if(!result.getSuccess()){
            throw new BizException(result.getMsg(),0);
        }

        Long productId = keyWorker.nextId();
        String proSerialNo;
        try {

            proSerialNo = bs.updateBillNumberByCode("CP");
        }catch (BizException e){
            logger.error("获取产品编号失败！" + e.getLocalizedMessage());
            throw new BizException("获取渠道编号失败",10001);
        }

        if(isPush){
            vo.getProduct().setStatus(1); //上架
        }else {
            vo.getProduct().setStatus(2); //待上架
        }
        /** ----------------------------------*/
        vo.getProduct().setCreaterId(currUser.getId());
        vo.getProduct().setCreaterName(currUser.getName()+currUser.getLoginName());
        vo.getProduct().setCreaterOrgId(currUser.getDeptId());
        vo.getProduct().setCreateTime(new Date());

        vo.getProduct().setUpdaterId(currUser.getId());
        vo.getProduct().setUpdaterName(currUser.getName() + currUser.getLoginName());
        vo.getProduct().setUpdaterOrgId(currUser.getDeptId());
        vo.getProduct().setUpdateTime(new Date());
        /** ----------------------------------*/

        vo.getProduct().setId(productId);
        vo.getProduct().setInitialId(productId);
        vo.getProduct().setVersion(1); //初始版本
        vo.getProduct().setSerialNo(proSerialNo);
        repository.save(vo.getProduct());

        for(ProductAreaPrice pap : vo.getProductAreaPrices()){
            Long productAreaId = keyWorker.nextId();
            pap.setId(productAreaId);
            pap.setProductId(productId);


            pap.setCreaterId(currUser.getId());
            pap.setCreaterName(currUser.getName() + currUser.getLoginName());
            pap.setCreaterOrgId(currUser.getDeptId());
            pap.setCreateTime(new Date());

            pap.setUpdaterId(currUser.getId());
            pap.setUpdaterName(currUser.getName() + currUser.getLoginName());
            pap.setUpdaterOrgId(currUser.getDeptId());
            pap.setUpdateTime(new Date());


            repository.save(pap);
        }

        for(ProductCondition pc : vo.getProductConditions() ){
            Long productConditionId = keyWorker.nextId();
            pc.setId(productConditionId);
            pc.setProductId(productId);

            pc.setCreaterId(currUser.getId());
            pc.setCreaterName(currUser.getName());
            pc.setCreaterOrgId(currUser.getDeptId());
            pc.setCreateTime(new Date());

            pc.setUpdaterId(currUser.getId());
            pc.setUpdaterName(currUser.getName());
            pc.setUpdaterOrgId(currUser.getDeptId());
            pc.setUpdateTime(new Date());

            repository.save(pc);
        }
    }

    /**
     *@Description: 修改产品包含区域价格和准入条件，将修改后的产品产品新增，修改前的产品设置为隐藏，异常抛出BizException
     *@Author: litao
     *@Param: vo ： 修改的实体对象（包含：Product、ProductAreaPrice、ProductCondition） <br />
     *@Date:9:17 2017/11/7
     */
    public void updateOneDetailProduct(ProductVo vo,User currUser){
        TreeBook treeBook = treeBookService.queryTreeBookParentByCode(vo.getProduct().getProClass());
        vo.getProduct().setType(treeBook.getPcode());

        ValidateResult result = validateProductParam(vo);
        if(!result.getSuccess()){
            throw new BizException(result.getMsg(),0);
        }

        Product oldProduct = repository.get(Product.class,vo.getProduct().getId()); //根据传入的producId获取 数据库中原有的对象
        if(oldProduct.getStatus() == 4 || oldProduct.getVersion() < getMaxVersionById(oldProduct.getId()) ){
            throw new BizException("数据已经修改,请关闭此页面重新加载本条数据",0);
        }

        Integer oldVersion = oldProduct.getVersion();
        Long initId = oldProduct.getInitialId();
        String serialNo = oldProduct.getSerialNo();
        Integer oldStatus = oldProduct.getStatus();
        oldProduct.setStatus(4); //老产品标记为删除


        oldProduct.setUpdateTime(new Date());
        oldProduct.setUpdaterId(currUser.getId());
        oldProduct.setUpdaterName(currUser.getName() + currUser.getLoginName());
        oldProduct.setUpdaterOrgId(currUser.getDeptId());
        repository.saveOrUpdate(oldProduct);

        Long newProductId = keyWorker.nextId();

        vo.getProduct().setInitialId(initId);
        vo.getProduct().setId(newProductId);
        vo.getProduct().setVersion(oldVersion + 1);
        vo.getProduct().setStatus(oldStatus); //是否修改后的产品设置为上架 1 ？
        vo.getProduct().setSerialNo(serialNo);


        /** ----------------------------------*/
        vo.getProduct().setCreaterId(currUser.getId());
        vo.getProduct().setCreaterName(currUser.getName() + currUser.getLoginName());
        vo.getProduct().setCreaterOrgId(currUser.getDeptId());
        vo.getProduct().setCreateTime(new Date());

        vo.getProduct().setUpdaterId(currUser.getId());
        vo.getProduct().setUpdaterName(currUser.getName() + currUser.getLoginName());
        vo.getProduct().setUpdaterOrgId(currUser.getDeptId());
        vo.getProduct().setUpdateTime(new Date());
        /** ----------------------------------*/


        repository.save(vo.getProduct());
        for(ProductAreaPrice pap : vo.getProductAreaPrices()) {

            pap.setId(keyWorker.nextId());
            pap.setProductId(newProductId);


            pap.setCreaterId(currUser.getId());
            pap.setCreaterName(currUser.getName()+currUser.getLoginName());
            pap.setCreaterOrgId(currUser.getDeptId());
            pap.setCreateTime(new Date());

            pap.setUpdaterId(currUser.getId());
            pap.setUpdaterName(currUser.getName()+currUser.getLoginName());
            pap.setUpdaterOrgId(currUser.getDeptId());
            pap.setUpdateTime(new Date());


            repository.save(pap);
        }
        for(ProductCondition pc : vo.getProductConditions() ){
            pc.setId(keyWorker.nextId());
            pc.setProductId(newProductId);

            pc.setCreaterId(currUser.getId());
            pc.setCreaterName(currUser.getName() + currUser.getLoginName());
            pc.setCreaterOrgId(currUser.getDeptId());
            pc.setCreateTime(new Date());

            pc.setUpdaterId(currUser.getId());
            pc.setUpdaterName(currUser.getName() + currUser.getLoginName());
            pc.setUpdaterOrgId(currUser.getDeptId());
            pc.setUpdateTime(new Date());

            repository.save(pc);
        }


    }

    //TODO 存在事务回滚问题
    public void batchPushByIds(Long[] ids){
        if(null != ids && ids.length > 0){
            for(Long currentId : ids){
                Product product = repository.get(Product.class,currentId);
                product.setStatus(1); //上架标志
                repository.saveOrUpdate(product);
            }
        }
    }
    //TODO 存在事务回滚问题
    public void batchUpdataProductByIds(Long[] ids,Integer status){
        if(null == status){
            return;
        }
        if(null != ids && ids.length > 0){
            for(Long currentId : ids){
                Product product = repository.get(Product.class,currentId);
                product.setStatus(status);
                repository.saveOrUpdate(product);
            }
        }
    }
    //TODO 存在事务回滚问题
    public void batchDeleteByIds(Long[] ids,User user){
        if(null != ids && ids.length > 0){
            for(Long currentId : ids){
                Product product = repository.get(Product.class,currentId);
                product.setStatus(4); //删除标志
                repository.saveOrUpdate(product);
            }
        }
    }
    //验证ProductVo
    private ValidateResult validateProductParam(ProductVo vo){
        Product product = vo.getProduct();
        ValidateResult result = new ValidateResult();
        result.setSuccess(true);
        if(null != product){
            if(StringUtils.isBlank(product.getType())){
                result.setSuccess(false);
                result.setMsg("'一级类别'不能为空");
                return result;
            }
            if(StringUtils.isBlank(product.getProClass())){
                result.setSuccess(false);
                result.setMsg("'二级类别'不能为空");
                return result;
            }

            if(null == product.getChannel()){
                result.setSuccess(false);
                result.setMsg("'渠道'不能为空");
                return result;
            }

            if(StringUtils.isBlank(product.getLevel())){
                result.setSuccess(false);
                result.setMsg("'产品级别'不能为空");
                return result;
            }
            if(StringUtils.isBlank(product.getName())){
                result.setSuccess(false);
                result.setMsg("'产品名称'不能为空");
                return result;
            }

//            if(null == product.getLoanAmountMin()){
//                result.setSuccess(false);
//                result.setMsg("'贷款金额最小值'不能为空");
//                return result;
//            }
//            if(null == product.getLoanAmountMax()){
//                result.setSuccess(false);
//                result.setMsg("'贷款金额最大值'不能为空");
//                return result;
//            }
            if(product.getLoanAmountMax()!=null && product.getLoanAmountMin() !=null &&
                    product.getLoanAmountMax() < product.getLoanAmountMin()){
                result.setSuccess(false);
                result.setMsg("'贷款金额最大值'不能小于'贷款金额最小值'");
                return result;
            }

//            if(null == product.getLoanLifeMin()){
//                result.setSuccess(false);
//                result.setMsg("'贷款年限最小值'不能为空");
//                return result;
//            }
//            if(null == product.getLoanLifeMax()){
//                result.setSuccess(false);
//                result.setMsg("'贷款年限最大值'不能为空");
//                return result;
//            }
            if(product.getLoanLifeMax()!=null && product.getLoanLifeMin()!=null&&
                    product.getLoanLifeMax() < product.getLoanLifeMin()){
                result.setSuccess(false);
                result.setMsg("'贷款年限最大值'不能小于'贷款年限最小值'");
                return result;
            }

//            if(null == product.getLoanInterestRateMin()){
//                result.setSuccess(false);
//                result.setMsg("'贷款利率最小值'不能为空");
//                return result;
//            }
//
//            if(null == product.getLoanInterestRateMax()){
//                result.setSuccess(false);
//                result.setMsg("'贷款利率最大值'不能为空");
//                return result;
//            }
            if(product.getLoanInterestRateMax()!=null&&product.getLoanInterestRateMin()!=null&&
                    product.getLoanInterestRateMax() < product.getLoanInterestRateMin()){
                result.setSuccess(false);
                result.setMsg("'贷款利率最大值'不能小于'贷款利率最小值'");
                return result;
            }

//            if(StringUtils.isBlank(product.getInterestRateMode())){
//                result.setSuccess(false);
//                result.setMsg("'利率方式'不能为空");
//                return result;
//            }

//            if(null == product.getLoanCycleMin()){
//                result.setSuccess(false);
//                result.setMsg("'放款周期最小值'不能为空");
//                return result;
//            }
//
//            if(null == product.getLoanCycleMax()){
//                result.setSuccess(false);
//                result.setMsg("'放款周期最大值'不能为空");
//                return result;
//            }
            if(product.getLoanCycleMax()!=null&&product.getLoanCycleMin()!=null&&
                    product.getLoanCycleMax() < product.getLoanCycleMin()){
                result.setSuccess(false);
                result.setMsg("'放款周期最大值'不能小于'放款周期最小值'");
                return result;
            }

//            if(StringUtils.isBlank(product.getRepaymentMode())){
//                result.setSuccess(false);
//                result.setMsg("'还款方式'不能为空");
//                return result;
//            }

//            if(null == product.getAgeMin()){
//                result.setSuccess(false);
//                result.setMsg("'年龄要求（下限）'不能为空");
//                return result;
//            }
//
//            if(null == product.getAgeMax()){
//                result.setSuccess(false);
//                result.setMsg("'年龄要求（上限）'不能为空");
//                return result;
//            }

            if(product.getAgeMin()!=null&&product.getAgeMax()!=null&&product.getAgeMin() > product.getAgeMax() ){
                result.setSuccess(false);
                result.setMsg("'年龄要求（上限）'不能小于'年龄要求（下限）'");
                return result;
            }

//            if(StringUtils.isBlank(product.getCreditRequire())){
//                result.setSuccess(false);
//                result.setMsg("'征信要求'不能为空");
//                return result;
//            }
            if(StringUtils.isBlank(product.getIsStandard())){
                result.setSuccess(false);
                result.setMsg("请选择'是否标件'");
                return result;
            }
        }else {
            result.setSuccess(false);
            result.setMsg("请仔细检查数据");
            return result;
        }

        if(null != vo.getProductAreaPrices() && vo.getProductAreaPrices().size() > 0){
            for(ProductAreaPrice pap : vo.getProductAreaPrices()){
//                if(StringUtils.isBlank(pap.getArea())){
//                    result.setSuccess(false);
//                    result.setMsg("'区域名'不能为空");
//                    return result;
//                }

                if(StringUtils.isBlank(pap.getChargeType())){
                    result.setSuccess(false);
                    result.setMsg("'手续费方式'不能为空");
                    return result;
                }
                if("PRO_SXFFS_DJ".equals(pap.getChargeType())){
                    if(null == pap.getStandardPrice()){
                        result.setSuccess(false);
                        result.setMsg("'定价'时'标准手续费'不能为空");
                        return result;
                    }
                }
                if(null != pap.getPriceMin() && null != pap.getStandardPrice() && pap.getPriceMin() > pap.getStandardPrice() ){
                    result.setSuccess(false);
                    result.setMsg("'标准手续费'不能小于'价格下限'");
                    return result;
                }
                if(null != pap.getPriceMin() && null != pap.getPriceMax() && pap.getPriceMin() > pap.getPriceMax()){
                    result.setSuccess(false);
                    result.setMsg("'价格上限'不能小于'价格下限'");
                    return result;
                }

                if(null != pap.getStandardPrice() && null != pap.getPriceMax() && pap.getPriceMax() < pap.getStandardPrice()){
                    result.setSuccess(false);
                    result.setMsg("'标准手续费'不能大于'价格上限'");
                    return result;
                }
//                if(null == pap.getStandardPrice()){
//                    result.setSuccess(false);
//                    result.setMsg("'标准手续费'不能为空");
//                    return result;
//                }
//                if(null == pap.getPriceMax()){
//                    result.setSuccess(false);
//                    result.setMsg("'手续费上限'不能为空");
//                    return result;
//                }
//                if(null == pap.getPriceMin()){
//                    result.setSuccess(false);
//                    result.setMsg("'手续费下限'不能为空");
//                    return result;
//                }
//
//                if(pap.getPriceMax() < pap.getStandardPrice()){
//                    result.setSuccess(false);
//                    result.setMsg("'手续费上限'不能小于'标准手续费'");
//                    return result;
//                }
//                if(pap.getPriceMax() < pap.getPriceMin()){
//                    result.setSuccess(false);
//                    result.setMsg("'手续费上限'不能小于'手续费下限'");
//                    return result;
//                }
//                if(pap.getStandardPrice() < pap.getPriceMin()){
//                    result.setSuccess(false);
//                    result.setMsg("'标准手续费'不能小于'手续费下限'");
//                    return result;
//                }


//                if(null == pap.getDownPayment()){
//                    result.setSuccess(false);
//                    result.setMsg("'定金'不能为空");
//                    return result;
//                }
//                if(null == pap.getPenalty()){
//                    result.setSuccess(false);
//                    result.setMsg("'违约金'不能为空");
//                    return result;
//                }
//                if(null == pap.getInternalCost()){
//                    result.setSuccess(false);
//                    result.setMsg("'内部成本'不能为空");
//                    return result;
//                }
//                if(null == pap.getOuterCost()){
//                    result.setSuccess(false);
//                    result.setMsg("'外部成本'不能为空");
//                    return result;
//                }
//                if(null == pap.getChannelRebate()){
//                    result.setSuccess(false);
//                    result.setMsg("'渠道返点'不能为空");
//                    return result;
//                }

            }
        }else {
            result.setSuccess(false);
            result.setMsg("请选择适用区域");
            return result;
        }

        if(null != vo.getProductConditions() && vo.getProductConditions().size() > 0){
//            for(ProductCondition pc : vo.getProductConditions()){
//                if(StringUtils.isBlank(pc.getMode())){
//                    result.setSuccess(false);
//                    result.setMsg("请选择'进件方式'");
//                    return result;
//                }
//                if(StringUtils.isBlank(pc.getAsset())){
//                    result.setSuccess(false);
//                    result.setMsg("'资产要求'不能为空");
//                    return result;
//                }
//                if(StringUtils.isBlank(pc.getAssetDetail())){
//                    result.setSuccess(false);
//                    result.setMsg("'资产准入条件'不能为空");
//                    return result;
//                }
//
//                if(StringUtils.isBlank(pc.getNeedData())){
//                    result.setSuccess(false);
//                    result.setMsg("请选择'所需资料'");
//                    return result;
//                }
//            }
        }else{
//            result.setSuccess(false);
//            result.setMsg("请仔细检查数据");
//            return result;
        }

        return result;

    }
}
